package com.ly.system.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.ly.config.response.Result;
import com.ly.system.entity.TbRole;
import com.ly.system.entity.TbUser;
import com.ly.system.service.TbRoleService;
import com.ly.system.vo.TbRoleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author jiangzhu
 * @since 2020-10-27
 */
@Api(value = "角色管理列表")
@RestController
@RequestMapping("/Role")
public class TbRoleController {

    @Resource
    private TbRoleService tbRoleService;

    @PostMapping("/findRole")
    @ApiOperation(value = "查询所有角色",notes = "分页+条件查询所有角色信息")
    private Result findRoleList(@RequestParam(defaultValue ="1",required = true) Integer current,
                                @RequestParam(required = true,defaultValue = "8")Integer size,
                                @RequestBody  TbRoleVO roleVo){
        Page<TbRole> page=new Page<>(current,size);
        QueryWrapper<TbRole> wrapper=new QueryWrapper<>();
        if(!StringUtils.isEmpty(roleVo.getRoleName())){
            wrapper.like("role_name",roleVo.getRoleName());
        }
        IPage<TbRole> rolePage = tbRoleService.page(page, wrapper);
        long total = rolePage.getTotal();
        List<TbRole> records = rolePage.getRecords();
        return Result.ok().data("total",total).data("records",records);
    }
}

